
const protecteds = new WeakMap()
// 也可以统一定义私有属性


class Common {
  constructor(host) {
    this.host = host
    protecteds.set(this, {
      host: this.host
    })
  }

  set host(url) {
    if (!/^https?:\/\//i.test(url)) {
      throw new Error("网址错误");
    }
    protecteds.set(this, {...protecteds.get(this), host:url})
  }

  get host() {
    return protecteds.get(this).host
  }

}

class Article extends Common {
  lists() {
    return `${this.host}/article`;
  }
}
var article = new Article('http://baidu.com');
console.log(article.lists()); //https://houdunren.com/article
article.host = "https://hdcms.com";
console.log(article.lists()); //https://hdcms.com/article

console.log('-----------------------\n')
console.log(article)
console.log(article.lists()); //https://hdcms.com/article
console.log(protecteds)

console.log('\n----------------------------------------------\n')

var article = new Article('http://qq.com');
console.log(article.lists()); //https://houdunren.com/article
article.host = "https://qqlive.com";
console.log(article.lists()); //https://hdcms.com/article
console.log(protecteds)


